//
//  ZZViewUtils.m
//  QQplayground
//
//  Created by zhangxy on 2018/5/24.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZViewUtils.h"

@implementation ZZViewUtils

+(ZTextField *)createZTextField:(NSString *)placeholder{
    ZTextField *backBtn = [[ZTextField alloc] initWithImage:nil padding:5];
    [backBtn setFrame:CGRectMake(20, 0, ScreenWidth-40, 52)];
    [backBtn setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    backBtn.layer.cornerRadius = 10.0f;
    backBtn.layer.masksToBounds = YES;
    [backBtn setFont:FontSeventeen];
    [backBtn setPlaceholder:placeholder];
    return backBtn;
}

+(ZTextField *)createZTextField:(NSString *)placeholder padding:(CGFloat) p{
    ZTextField *backBtn = [[ZTextField alloc] initWithImage:nil padding:p];
    [backBtn setFrame:CGRectMake(20, 0, ScreenWidth-40, 52)];
    [backBtn setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    backBtn.layer.cornerRadius = 10.0f;
    backBtn.layer.masksToBounds = YES;
    [backBtn setFont:FontSeventeen];
    [backBtn setPlaceholder:placeholder];
    return backBtn;
}


+(void)cutViewRound:(UIView *) view radius:(CGFloat ) radius byRoundingCorners:(UIRectCorner)corners{
    //设置切哪个直角
    //    UIRectCornerTopLeft     = 1 << 0,  左上角
    //    UIRectCornerTopRight    = 1 << 1,  右上角
    //    UIRectCornerBottomLeft  = 1 << 2,  左下角
    //    UIRectCornerBottomRight = 1 << 3,  右下角
    //    UIRectCornerAllCorners  = ~0UL     全部角
    //得到view的遮罩路径
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius,radius)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = view.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    view.layer.mask = maskLayer;
}



//用户等级的显示问题
+(void)setBtnLevelColor:(User *) user btn:(UIButton *) _btnLevel{
    int level = [user.group_icon intValue];
    if (level >= 1 && level < 6){
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"1"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 1"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv 0%@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#A4A4A4" alpha:1.0] forState:0];
    } else if (level >= 6 && level < 11) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"2"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 2"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#1BC156" alpha:1.0] forState:0];
    } else if (level >= 11 && level < 16) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"3"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 3"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#4A90E2" alpha:1.0] forState:0];
    } else if (level >= 16 && level < 21) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 4"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#8D6FFF" alpha:1.0] forState:0];
    } else if (level >= 21 && level < 26) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"5"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 5"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF9300" alpha:1.0] forState:0];
    } else if (level >= 26 && level < 31) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"5"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 6"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF9300" alpha:1.0] forState:0];
    } else if (level >= 31 && level < 36) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"7"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 7"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0] forState:0];
    } else if (level >= 36 && level < 41) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"8"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 8"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#3785FF" alpha:1.0] forState:0];
    } else if (level >= 41 && level < 46) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 9"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#962BFF" alpha:1.0] forState:0];
    } else if (level >= 46 && level < 51) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 10"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
    } else if (level >= 51 && level < 56) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"11"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 11"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0] forState:0];
    } else if (level >= 56) {
        [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"12"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,10) resizingMode:UIImageResizingModeStretch]  forState:0 ];
        [_btnLevel setImage:[UIImage imageNamed:@"Star 12"] forState:0];
        [_btnLevel setTitle:[NSString stringWithFormat:@"  Lv %@",user.group_icon] forState:0];
        [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFFFFF" alpha:1.0] forState:0];
    }
    [_btnLevel setContentEdgeInsets:UIEdgeInsetsMake(2, 0, 2, 0)];
}

@end
